<template>
    <div class="grandChildClass">
        <h4>Grand child</h4>
        <button @click="openDialog">Open dialog</button>
        <!-- 将 Teleport 包裹的组件传送到 html 标签上去 to=选择器语法 -->
        <Teleport to="html">
            <div class="mask" v-if='isShowDialog'>
                <div class="dialog">
                    <button @click="closeDialog">Close dialog</button>
                </div>
            </div>

        </Teleport>

    </div>
</template>

<script>
import { ref } from 'vue';

export default {
    name: 'GrandChildComponent',
    setup() {
        let isShowDialog = ref(false)

        const openDialog = () => {
            isShowDialog.value = true
        }

        const closeDialog = () => {
            isShowDialog.value = false
        }
        return {
            isShowDialog,
            openDialog,
            closeDialog
        }
    }
}
</script>

<style>
.grandChildClass {
    background-color: aqua;
    padding: 10px;
}

.dialog {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: rgb(250, 250, 250);
    width: 300px;
    height: 300px;
    border: 3px solid rgb(50, 50, 50);
    border-radius: 5%;
    margin: 5px;
}

.mask {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 50%)
}
</style>